package com.muqi.app.qlearn.publish;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.jivesoftware.smack.util.dns.SRVRecord;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.loopj.android.http.RequestParams;
import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.bean.ImageItem;
import com.lzy.imagepicker.loader.GlideImageLoader;
import com.lzy.imagepicker.ui.ImageGridActivity;
import com.muqi.app.modle.bean.BMapAddress;
import com.muqi.app.network.http.MyAsyncHttp;
import com.muqi.app.network.http.MyAsyncHttp.RESULTCODE;
import com.muqi.app.network.http.ParamsUtils;
import com.muqi.app.network.http.MyAsyncHttp.AsyncCallBackListener;
import com.muqi.app.network.http.MyAsyncHttp.AsyncWithProgressListener;
import com.muqi.app.project.contants.MContants;
import com.muqi.app.project.contants.NetWorkApi;
import com.muqi.app.project.utils.PictureUtil;
import com.muqi.app.qlearn.adapter.NinePhotosAdapter;
import com.muqi.app.qlearn.modles.RecordTypeBean;
import com.muqi.app.qlearn.student.BMapActivity;
import com.muqi.app.qlearn.student.BaseFragmentActivity;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.user.widget.MyGridView;
import com.muqi.app.user.widget.RecordDateEntry;
import com.muqi.app.user.widget.RecordEdtEntry;
import com.muqi.app.user.widget.RecordLevelEntry;
import com.muqi.app.user.widget.RecordTypeWindow;
import com.wenhui.pedant.SweetAlert.SweetAlertDialog;
import com.wenhui.pedant.SweetAlert.SweetAlertDialog.OnSweetClickListener;

public class WriteRecordActivity extends BaseFragmentActivity implements
		OnClickListener, OnItemClickListener,
		NinePhotosAdapter.OnDeleteListener,
		RecordTypeWindow.OnConfirmSelectListener {
	private static final int REQUEST_BMAP_CODE = 10001;
	private static final int REQUEST_AUTHOR_CODE = 10002;
	private LinearLayout contentAddLayout;
	private Button confirmButton;
	private MyGridView picGridView;
	private ImagePicker imagePicker;
	private EditText et_content;
	private TextView typeText;
	private TextView selectAddress;
	private TextView authorText;
	private int picLimit = 9;
	/*** 上传图片array */
	private ArrayList<String> hasUploadUrls = new ArrayList<String>();
	private ArrayList<String> hasUploadNames = new ArrayList<String>();
	private ArrayList<String> needUploadUrls = new ArrayList<String>();
	private List<ImageItem> postImages = new ArrayList<ImageItem>();
	private NinePhotosAdapter mAdapter = null;

	/* 对应type的数据 */
	private ArrayList<String> typeDataKey = new ArrayList<String>();
	private ArrayList<String> typeDataValue = new ArrayList<String>();
	private int typeDataScore;

	private int type;
	private RecordTypeWindow typeWindow = null;
	private RecordTypeBean getType = null;

	private String authority = "PUBLIC";
	private boolean isSetPriazeType=true;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		imagePicker = ImagePicker.getInstance();
		imagePicker.setImageLoader(new GlideImageLoader());// 设置图片加载器
		imagePicker.setShowCamera(true); // 显示拍照按钮
		imagePicker.setCrop(false); // 允许裁剪（单选才有效）
		imagePicker.setSaveRectangle(true); // 是否按矩形区域保存
		imagePicker.setSelectLimit(picLimit); // 选中数量限制
		imagePicker.setMultiMode(true);
		setContentView(R.layout.aty_write_record);
	}

	@Override
	protected void onInit() {
		contentAddLayout = (LinearLayout) findViewById(R.id.contentLayout);
		picGridView = (MyGridView) findViewById(R.id.picture_gridview);
		picGridView.setOnItemClickListener(this);
		confirmButton = (Button) findViewById(R.id.saveContentButton);
		confirmButton.setOnClickListener(this);
		et_content = (EditText) findViewById(R.id.content_edttext);
		typeText = (TextView) findViewById(R.id.type_text);
		selectAddress = (TextView) findViewById(R.id.select_address_text);
		authorText = (TextView) findViewById(R.id.select_users_text);
	}

	@Override
	protected void onData() {
		Intent intent = getIntent();
		if (intent != null) {
			ArrayList<ImageItem> temp = (ArrayList<ImageItem>) intent
					.getSerializableExtra("pics");
			if (temp != null) {
				postImages.addAll(temp);

			}
		}
		if (postImages.size() < 9) {
			picLimit=9-postImages.size();
			imagePicker.setSelectLimit(picLimit);
			ImageItem button = new ImageItem();
			button.name = MContants.PICTURE_VIEW_BUTTON;
			button.path = "Add_Button";
			postImages.add(button);
			
		}
		mAdapter = new NinePhotosAdapter(this, postImages, this);
		picGridView.setAdapter(mAdapter);
		
	}

	public void onBack(View v){
		
		new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
		.setTitleText("退出此次记录")
		.setCancelText("取消")
		.setConfirmText("确定")
		.showCancelButton(true)
		.setCancelClickListener(new OnSweetClickListener() {
			@Override
			public void onClick(SweetAlertDialog mDialog) {
				mDialog.dismissWithAnimation();
			}
		})
		.setConfirmClickListener(new OnSweetClickListener() {
			@Override
			public void onClick(SweetAlertDialog mDialog) {
				WriteRecordActivity.this.finish();
			}
		}).show();
	}
	
	
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position,
			long arg3) {
		if (postImages.get(position).path.equals("Add_Button")) {
			imagePicker.setSelectLimit(picLimit);
			Intent intent = new Intent(this, ImageGridActivity.class);
			startActivityForResult(intent, MContants.SELECT_WECHAT_DCIM_CODE);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.saveContentButton:
			if (getType == null) {
				showToast("还未选择记录类型");
				return;
			}
			if(postImages==null || postImages.size()<=1){
				showToast("至少选择一张图片");
				return;
			}
			if (TextUtils.isEmpty(et_content.getText())) {
				Toast.makeText(mContext, "内容不能为空！", Toast.LENGTH_SHORT).show();
			} else {
			
				getTypeData();
				if(typeDataScore==0){
				
				   showToast("请选择获奖类别");
					
					return;
				}

				needUploadUrls.clear();
				for (ImageItem item : postImages) {

					if (!MContants.PICTURE_VIEW_BUTTON.equals(item.name)) {
						needUploadUrls.add(item.path);
					}
				}
				if (needUploadUrls.size() == 0) {
					confirmButton.setEnabled(false);
					upLoadingRecord();
				} else {
					confirmButton.setEnabled(false);
					setMaxPicsSvWithProgress(needUploadUrls.size(), "记录发布中");
					upLoadingPictures(needUploadUrls.get(0), 0);
				}
			}
			break;
		default:
			break;
		}
	}


	// 所在位置
	public void onSelectAddress(View v) {
		Intent intent = new Intent(this, BMapActivity.class);
		startActivityForResult(intent, REQUEST_BMAP_CODE);
	}

	// 谁可以看
	public void onSelectUsers(View v) {
		Intent intent = new Intent(this, WriteAuthorityActivity.class);
		startActivityForResult(intent, REQUEST_AUTHOR_CODE);
	}

	// 提醒谁看
	public void onWarningUsers(View v) {

	}

	// 类别
	public void onSelectType(View v) {
		if (typeWindow == null) {
			typeWindow = new RecordTypeWindow(this, this);
		}
		typeWindow.showAsDropDown(v);
	}

	@Override
	public void onConfirmSelect(RecordTypeBean selecter) {
		Log.e("===", selecter.name+" "+selecter.position);
		getType = selecter;
		typeText.setText(selecter.name + "");
		type = selecter.position;
		selectDifferentTypes(type);
	}

	private void selectDifferentTypes(int type) {
		contentAddLayout.removeAllViews();
		// 输入类型
		RecordEdtEntry edtcontent1 = null;
		RecordEdtEntry edtcontent2 = null;
		RecordEdtEntry edtcontent3 = null;
		RecordEdtEntry edtcontent4 = null;
		RecordEdtEntry edtcontent5 = null;
		RecordEdtEntry edtcontent6 = null;
		RecordEdtEntry edtcontent7 = null;
		RecordEdtEntry edtcontent8 = null;
		RecordEdtEntry edtcontent9 = null;
		RecordEdtEntry edtcontent10 = null;
		RecordEdtEntry edtcontent11 = null;
		RecordEdtEntry edtcontent12 = null;
		// 选择日期类型
		RecordDateEntry datecontent1 = null;
		RecordDateEntry datecontent2 = null;

		// 选择列表类型
		RecordLevelEntry levelcontent1 = null;
		RecordLevelEntry levelcontent2 = null;
		switch (type) { // 依次按excel表格：从左到右
		case 1:// 公益劳动
			edtcontent1 = new RecordEdtEntry(this, "年级");
			levelcontent1 = new RecordLevelEntry(this, "学期", new String[] {
					"上学期", "下学期" });
			edtcontent3 = new RecordEdtEntry(this, "活动简要");
			datecontent1 = new RecordDateEntry(this, "参加时间");
			// RecordTimeEntry content5 = new RecordTimeEntry(this, "参加时间");
			contentAddLayout.addView(edtcontent1);
			contentAddLayout.addView(levelcontent1);
			contentAddLayout.addView(edtcontent3);
			contentAddLayout.addView(datecontent1);
			// contentAddLayout.addView(content5);
			break;
		case 2:// 学校党团（社团）
		case 3:// 民族团结,活动
			edtcontent1 = new RecordEdtEntry(this, "年级");
			levelcontent1 = new RecordLevelEntry(this, "学期", new String[] {
					"上学期", "下学期" });
			edtcontent3 = new RecordEdtEntry(this, "社团活动情况");
			edtcontent4 = new RecordEdtEntry(this, "任职或分工");
			datecontent1 = new RecordDateEntry(this, "参加时间");
			// RecordTimeEntry content5 = new RecordTimeEntry(this, "参加时间");
			contentAddLayout.addView(edtcontent1);
			contentAddLayout.addView(levelcontent1);
			contentAddLayout.addView(edtcontent3);
			contentAddLayout.addView(edtcontent4);
			contentAddLayout.addView(datecontent1);
			break;
		case 4: // 必修课程

			break;
		case 5:// 学业水平考试

			break;
		case 6:
			break;
		case 7:// 研究性学习

			break;
		case 8:// 学科竞赛
			edtcontent1 = new RecordEdtEntry(this, "奖项");
			levelcontent1 = new RecordLevelEntry(this, "等级", new String[] {
					"校级", "区县级", "市级", "省级" });
			datecontent1 = new RecordDateEntry(this, "获奖时间");
			edtcontent2 = new RecordEdtEntry(this, "颁证单位");

			contentAddLayout.addView(edtcontent1);
			contentAddLayout.addView(levelcontent1);
			contentAddLayout.addView(datecontent1);
			contentAddLayout.addView(edtcontent2);
			break;
		case 9:

			break;
		case 10: // 体育特长项目
			edtcontent1 = new RecordEdtEntry(this, "年级");
			levelcontent1 = new RecordLevelEntry(this, "学期", new String[] {
					"上学期", "下学期" });

			levelcontent2 = new RecordLevelEntry(this, "等级", new String[] {
					"校级", "区县级", "市级", "省级" });

			datecontent1 = new RecordDateEntry(this, "获奖时间");
			edtcontent3 = new RecordEdtEntry(this, "颁证单位");

			contentAddLayout.addView(edtcontent1);
			contentAddLayout.addView(levelcontent1);
			contentAddLayout.addView(levelcontent2);
			contentAddLayout.addView(datecontent1);
			contentAddLayout.addView(edtcontent3);
			break;
		case 11:

			break;
		case 12: // 体育比赛
			edtcontent1 = new RecordEdtEntry(this, "年级");
			edtcontent2 = new RecordEdtEntry(this, "参加项目");
			edtcontent3 = new RecordEdtEntry(this, "获奖情况");
			levelcontent1 = new RecordLevelEntry(this, "等级", new String[] {
					"校级", "区县级", "市级", "省级" });

			contentAddLayout.addView(edtcontent1);
			contentAddLayout.addView(edtcontent2);
			contentAddLayout.addView(edtcontent3);
			contentAddLayout.addView(levelcontent1);

			break;

		case 13: // 艺术活动
			edtcontent1 = new RecordEdtEntry(this, "年级");
			edtcontent2 = new RecordEdtEntry(this, "具体内容");

			datecontent1 = new RecordDateEntry(this, "开始时间");
			datecontent2 = new RecordDateEntry(this, "结束时间");

			edtcontent3 = new RecordEdtEntry(this, "社团名称");
			edtcontent4 = new RecordEdtEntry(this, "担任角色");

			contentAddLayout.addView(edtcontent1);
			contentAddLayout.addView(edtcontent2);

			contentAddLayout.addView(datecontent1);
			contentAddLayout.addView(datecontent2);

			contentAddLayout.addView(edtcontent3);
			contentAddLayout.addView(edtcontent4);

			break;
		case 14: // 艺术活动获奖情况
			edtcontent1 = new RecordEdtEntry(this, "年级");
			edtcontent2 = new RecordEdtEntry(this, "获奖情况");
			levelcontent1 = new RecordLevelEntry(this, "获奖等级", new String[] {
					"校级", "区县级", "市级", "省级" });

			contentAddLayout.addView(edtcontent1);
			contentAddLayout.addView(edtcontent2);
			contentAddLayout.addView(levelcontent1);
			break;
		case 15:// 军事训练
			edtcontent1 = new RecordEdtEntry(this, "训练名称");

			levelcontent1 = new RecordLevelEntry(this, "等级", new String[] {
					"校级", "区县级", "市级", "省级" });

			datecontent1 = new RecordDateEntry(this, "训练时间");
			contentAddLayout.addView(edtcontent1);

			contentAddLayout.addView(levelcontent1);

			contentAddLayout.addView(datecontent1);

			break;
		case 16: // 研究性調查
			edtcontent1 = new RecordEdtEntry(this, "代表作标题");
			edtcontent2 = new RecordEdtEntry(this, "实践目的");
			edtcontent3 = new RecordEdtEntry(this, "指导老师");
			edtcontent4 = new RecordEdtEntry(this, "合作者");
			edtcontent5 = new RecordEdtEntry(this, "个人角色");
			edtcontent6 = new RecordEdtEntry(this, "具体任务");
			edtcontent7 = new RecordEdtEntry(this, "学校认定意见");
			edtcontent8 = new RecordEdtEntry(this, "研究结论和反思");
			edtcontent9 = new RecordEdtEntry(this, "指导老师的简要评论");

			datecontent1 = new RecordDateEntry(this, "开始时间");
			datecontent2 = new RecordDateEntry(this, "结束时间");

			edtcontent10 = new RecordEdtEntry(this, "采访（请教）过的重点对象");
			edtcontent11 = new RecordEdtEntry(this, "本成果公开交流情况");
			edtcontent12 = new RecordEdtEntry(this, "本成果获奖情况");

			levelcontent1 = new RecordLevelEntry(this, "等级", new String[] {
					"校级", "区县级", "市级", "省级" });
			// RecordTimeEntry content5 = new RecordTimeEntry(this, "参加时间");
			contentAddLayout.addView(edtcontent1);
			contentAddLayout.addView(edtcontent2);
			contentAddLayout.addView(edtcontent3);
			contentAddLayout.addView(edtcontent4);
			contentAddLayout.addView(edtcontent5);
			contentAddLayout.addView(edtcontent6);
			contentAddLayout.addView(edtcontent7);
			contentAddLayout.addView(edtcontent8);
			contentAddLayout.addView(edtcontent9);

			contentAddLayout.addView(datecontent1);
			contentAddLayout.addView(datecontent2);

			contentAddLayout.addView(edtcontent10);
			contentAddLayout.addView(edtcontent11);
			contentAddLayout.addView(edtcontent12);

			contentAddLayout.addView(levelcontent1);

			break;
		case 17:// 科技活动
		case 18:// 创造发明
			edtcontent1 = new RecordEdtEntry(this, "活动名称");
			edtcontent2 = new RecordEdtEntry(this, "主办单位");
			datecontent1 = new RecordDateEntry(this, "时间");
			edtcontent3 = new RecordEdtEntry(this, "获奖情况");
			levelcontent1 = new RecordLevelEntry(this, "获奖等级", new String[] {
					"校级", "区县级", "市级", "省级" });

			contentAddLayout.addView(edtcontent1);
			contentAddLayout.addView(edtcontent2);
			contentAddLayout.addView(datecontent1);
			contentAddLayout.addView(edtcontent3);
			contentAddLayout.addView(levelcontent1);
			break;
		default:
			break;
		}
	}

	private void upLoadingPictures(String filename, final int position) {
		try {
			HashMap<String, Object> sendMap = new HashMap<String, Object>();
			sendMap.put("token", mSpUtil.getToken());
			sendMap.put("class_manager_id", mSpUtil.getChildClassId());
			String requestStr = ParamsUtils.buildParams("", sendMap);
			
			RequestParams params = new RequestParams();
			params.put("data", requestStr);
			File file = PictureUtil.scalImageFile(filename);
			if (file.exists() && file.length() > 0) {
				params.put("uploadfile", file);
			}
			MyAsyncHttp.postWithProgress(this, params, NetWorkApi.UPLOAD_RECORD_PICTURES,
					new AsyncWithProgressListener() {

						@Override
						public void onProgress(int bytesWritten, int totalSize) {
							int progress = bytesWritten * 100 / totalSize;
							mSVProgressHUD.getProgressBar().setProgress(progress);
							mSVProgressHUD.setText("记录发布中 " + position + "/"
									+ needUploadUrls.size());
						}

						@Override
						public void onAsyncCallBack(RESULTCODE resuleCode, String request, String result) {

							if (resuleCode == RESULTCODE.SUCCESS) {
								try {
									JSONObject resultJosn = new JSONObject(result.toString());
									JSONObject mJosn = resultJosn.getJSONObject("data");
									hasUploadUrls.add(mJosn.getString("fileurl"));
									hasUploadNames.add(postImages.get(position).name);
									postImages.get(position).name = MContants.PICTURE_VIEW_BUTTON;// 每成功一张，标记一张，避免重复上传err
									if (position == needUploadUrls.size() - 1) {
										hidingSVloading();
										upLoadingRecord();
									} else {
										upLoadingPictures(
												needUploadUrls.get(position + 1),
												position + 1);
									}
								
								} catch (Exception e) {
									confirmButton.setEnabled(true);
									showErrorWithState();
								}
							} else {
								confirmButton.setEnabled(true);
								showErrorWithState();
							}

							
						}
					});
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == ImagePicker.RESULT_CODE_ITEMS) {
			if (data != null
					&& requestCode == MContants.SELECT_WECHAT_DCIM_CODE) {
				ArrayList<ImageItem> images = (ArrayList<ImageItem>) data
						.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
				if (images != null && images.size() > 0) {
					if (images.size() == 1 && picLimit == 9) {// 单张照片选择时，getview重复绘制导致button背景改变？？
						postImages.clear();
						picLimit = picLimit - 1;
						postImages.addAll(images);
						ImageItem button = new ImageItem();
						button.name = MContants.PICTURE_VIEW_BUTTON;
						button.path = "Add_Button";
						postImages.add(button);
						if (mAdapter != null)
							mAdapter = null;
						mAdapter = new NinePhotosAdapter(this, postImages, this);
						picGridView.setAdapter(mAdapter);
					} else {
						for (ImageItem item : images) {
							picLimit = picLimit - 1;
							postImages.add(postImages.size() - 1, item);
						}
						if (picLimit == 0) {
							postImages.remove(postImages.size() - 1);
						}
						if (mAdapter != null)
							mAdapter.notifyDataSetChanged();
					}
				}
			}
		} else if (requestCode == REQUEST_BMAP_CODE) {
			if (resultCode == RESULT_OK && data != null) {
				BMapAddress getAddress = (BMapAddress) data
						.getSerializableExtra(BMapActivity.BMAP_SELECT_DATA);
				if (getAddress != null) {
					selectAddress.setText(getAddress.getBMapAdress() + "");
				}
			}
		} else if (requestCode == REQUEST_AUTHOR_CODE) {
			if (resultCode == RESULT_OK && data != null) {
				authority = data
						.getStringExtra(WriteAuthorityActivity.SELECT_AUTHORITY_TYPE);
				if (authority.equals("PUBLIC")) {
					authorText.setText("公开");
				} else if (authority.equals("CLASS")) {
					authorText.setText("本班可见");
				} else if (authority.equals("PRIVATE")) {
					authorText.setText("私密");
				}
			}
		}
	}

	@Override
	public void onDeletePicture(int position) {
		postImages.remove(position);
		picLimit = picLimit + 1;
		if (picLimit == 1) {
			ImageItem button = new ImageItem();
			button.name = MContants.PICTURE_VIEW_BUTTON;
			button.path = "Add_Button";
			postImages.add(button);
		}
		if (mAdapter != null)
			mAdapter.notifyDataSetChanged();
	}

	/**
	 * 获取对应type的数据
	 */
	private void getTypeData() {
		int childCount = contentAddLayout.getChildCount();
		RelativeLayout childView = null;

		for (int i = 0; i < childCount; i++) {
			childView = (RelativeLayout) contentAddLayout.getChildAt(i);
			if (childView instanceof RecordEdtEntry) {
				typeDataKey
						.add(((RecordEdtEntry) childView).getTextViewValue());
				typeDataValue.add(((RecordEdtEntry) childView)
						.getEditTextValue());
				getScoreByType(((RecordEdtEntry) childView).getEditTextValue());
			} else if (childView instanceof RecordDateEntry) {
				typeDataKey.add(((RecordDateEntry) childView)
						.getTextViewValue());
				typeDataValue.add(((RecordDateEntry) childView)
						.getDateTextValue());
				getScoreByType(((RecordDateEntry) childView).getDateTextValue());

			} else if (childView instanceof RecordLevelEntry) {
				typeDataKey.add(((RecordLevelEntry) childView)
						.getTextViewValue());
				typeDataValue.add(((RecordLevelEntry) childView)
						.getDateTextValue());
				getScoreByType(((RecordLevelEntry) childView)
						.getDateTextValue());

			}
		}
		
	}

	/**
	 * 
	 * @return 获取分数
	 */
	private void getScoreByType(String levelValue) {
		switch (type) {
		case 1:
		case 2:
		case 3:
		case 13:
		case 15:
			typeDataScore = 5;
			break;
		case 5:
		case 8:
		case 10:
		case 12:
		case 14:
		case 16:
		case 17:
		case 18:
			if (levelValue != null && !"".equals(levelValue)) {
				if ("校级".equals(levelValue)) {
					typeDataScore = 10;
				} else if ("区县级".equals(levelValue)) {
					typeDataScore = 50;
				} else if ("市级".equals(levelValue)) {
					typeDataScore = 100;
				} else if ("省级".equals(levelValue)) {
					typeDataScore = 500;
				}
			}
			break;
		default:
			break;
		}

	}

	/**
	 * 上传记录
	 * 
	 */
	private void upLoadingRecord() {
		confirmButton.setEnabled(false);
		String postUrls = "";
		for (int i = 0; i < hasUploadUrls.size(); i++) {
			postUrls = postUrls + hasUploadUrls.get(i);
			if (i != hasUploadUrls.size() - 1) {
				postUrls = postUrls + ";";
			}
		}
		HashMap<String, Object> sendMap = new HashMap<String, Object>();
		sendMap.put("token", mSpUtil.getToken());
		sendMap.put("school_id", mSpUtil.getChildSchoolId());
		sendMap.put("grade_id",mSpUtil.getChildGradeId());
		sendMap.put("class_manager_id", mSpUtil.getChildClassId());
		sendMap.put("student_id", mSpUtil.getCurrentChildId());
		sendMap.put("fname", getType.bigType);
		sendMap.put("sname", getType.smallType);
		sendMap.put("tkey", typeDataKey);
		sendMap.put("tvalue", typeDataValue);
		sendMap.put("score", typeDataScore);
		sendMap.put("content", et_content.getText().toString());
		if (TextUtils.isEmpty(selectAddress.getText())
				|| selectAddress.getText().equals("所在位置")) {
			sendMap.put("address", "");
		} else {
			sendMap.put("address", selectAddress.getText());
		}
		sendMap.put("visibility", authority);
		sendMap.put("visible_users", "");
		sendMap.put("pics", postUrls);

		RequestParams params = new RequestParams();
		params.add("data", ParamsUtils.buildParams("", sendMap));
		MyAsyncHttp.post(mContext, params, NetWorkApi.UPLOAD_RECORD,
				new AsyncCallBackListener() {

					@Override
					public void onAsyncCallBack(RESULTCODE resuleCode, String request, String result) {
						confirmButton.setEnabled(true); // 恢复按钮的可用状态
						if (resuleCode == RESULTCODE.SUCCESS) {
							Log.e("===", result);
							Intent intent = new Intent();
							intent.setAction(MContants.REFRESH_FILETREE_ACTION);
							sendBroadcast(intent);
							
							setResult(RESULT_OK);
							finish();
						} else {
							showErrorWithState();
						}
					}
				});
	}

}
